package com.ndp.fb.walle.business.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.fb.rdb.api.EcProductElementStyleGroupRdbService;
import com.ndp.fb.rdb.model.ectemplate.EcProductElementStyleGroup;
import com.ndp.fb.walle.business.EcProductElementStyleGroupService;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by sisi.chen on 2016/7/12.
 */
@Component
public class EcProductElementStyleGroupServiceImpl implements EcProductElementStyleGroupService {

    @Reference
    private EcProductElementStyleGroupRdbService ecProductElementStyleGroupRdbService;

    @Override
    public synchronized EcProductElementStyleGroup saveNew(Long productId, Integer elementStyleGroupId) {
        EcProductElementStyleGroup ecProductElementStyleGroup =
                ecProductElementStyleGroupRdbService.findByProductIdAndElementStyleGroupId(productId, elementStyleGroupId);
        if (null == ecProductElementStyleGroup){
            ecProductElementStyleGroup = new EcProductElementStyleGroup();
            ecProductElementStyleGroup.setProductId(productId);
            ecProductElementStyleGroup.setElementStyleGroupId(elementStyleGroupId);
            ecProductElementStyleGroup.setTime(new Date().getTime());
            Long id = ecProductElementStyleGroupRdbService.save(ecProductElementStyleGroup);
            ecProductElementStyleGroup.setId(id);
        }
        return ecProductElementStyleGroup;
    }
}
